/**
 * 
 */
package edu.sjtu.seda.threadpool;

import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import edu.sjtu.seda.event.Event;
import edu.sjtu.seda.stage.Stage;
import edu.sjtu.seda.stage.StageWrapper;

/**
 * @author john.zhu
 *
 */
public class ThreadPoolImpl implements ThreadPool {
	
	private ExecutorService threadpool;
	private StageWrapper wrapper;
	private static int coreThreadPoolSize = 5;
	
	public ThreadPoolImpl(StageWrapper wrapper){
		this(wrapper,coreThreadPoolSize);
	}
	
	public ThreadPoolImpl(StageWrapper wrapper,int corePoolSize){
		if(threadpool!=null)
			throw new RuntimeException("Threadpool already exists!");
		this.coreThreadPoolSize = corePoolSize;
		threadpool = Executors.newFixedThreadPool(coreThreadPoolSize);
		this.wrapper = wrapper;
	}
	
	@Override
	public Future execute(Runnable runner) {
		return threadpool.submit(runner);
	}

	@Override
	public void shutdown() {
		threadpool.shutdown();
	}
	
}
